<!doctype html>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
<head>
    <meta charset="utf-8">
    <title>Spring MVC Hibrnate Basics</title>

    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
    <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
</head>

<body>

    <div class="container">
        <div class="row">
            <div class="span8 offset2">
                <h1>Stock</h1>
                <form:form method="post" action="Stock/add" commandName="stock" class="form-horizontal">
                <div class="control-group">
                    <form:label cssClass="control-label" path="name">Name:</form:label>
                    <div class="controls">
                        <form:input path="name"/>
                    </div>
                </div>
                <div class="control-group">
                    <form:label cssClass="control-label" path="symbol">Symbol:</form:label>
                    <div class="controls">
                        <form:input path="symbol"/>
                    </div>
                </div>
                <div class="control-group">
                    <form:label cssClass="control-label" path="sumary">Desc:</form:label>
                    <div class="controls">
                        <form:input path="sumary"/>
                    </div>
                </div>                    
                <div class="control-group">
                    <div class="controls">
                        <input type="submit" value="Add Stock" class="btn"/>
                        </form:form>
                    </div>
                </div>

                <c:if test="${!empty stock}">
                    <h3>Stock</h3>
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Symbol</th>
                                <th>Desc</th>
                                <th>&nbsp;</th>
                            </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${stockDao}" var="stock">
                            <tr>
                                <td>${stock.name}</td>                            
                                <td>${stock.symbol}</td>
                                <td>${stock.sumary}</td>
                                <td>
                                    <form action="Stock/delete/${stock.stock_id}" method="post">
                                        <input type="submit" class="btn btn-danger btn-mini" value="Delete"/>
                                    </form>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </c:if>
            </div>
        </div>
    </div>
                            
    </body>
</html>
